import React, { Component, Fragment } from "react";
import { formatMessage } from "umi-plugin-react/locale";
import { connect } from "dva";
import Link from "umi/link";
import { Icon } from "antd";
import GlobalFooter from "@/components/GlobalFooter";
import DocumentTitle from "react-document-title";
import SelectLang from "@/components/SelectLang";
import styles from "./UserLayout.less";
import logo from "../assets/logo.png";
import getPageTitle from "@/utils/getPageTitle";
import { getSystemPlatformInfo } from "@/services/platformManagement";
import bgUrl from "@/assets/loginBg.png"
import logoTitle from "@/assets/logoTitle.png"

const links = [
	/* {
    key: 'help',
    title: formatMessage({ id: 'layout.user.link.help' }),
    href: '',
  },
  {
    key: 'privacy',
    title: formatMessage({ id: 'layout.user.link.privacy' }),
    href: '',
  },
  {
    key: 'terms',
    title: formatMessage({ id: 'layout.user.link.terms' }),
    href: '',
  },*/
];

const copyright = (
	<Fragment>
		2014-2019 <Icon type='copyright' /> 智能机器人.
	</Fragment>
);

class UserLayout extends Component {
  constructor(props){
    super(props);
    this.state = {
      platform:{},

    }
  }
	componentDidMount() {
		const {
			dispatch,
			route: { routes, authority },
		} = this.props;
		dispatch({
			type: "menu/getMenuData",
			payload: { routes, authority },
		});
    this.getPlatformInfo();
	}

  getPlatformInfo = async () => {
    const res = await getSystemPlatformInfo();
    console.log(res);
    window.localStorage.setItem("platformInfo",JSON.stringify(res))
    this.setState({
      platform:res
    })
  }

  

	render() {
		const {
			children,
			location: { pathname },
			breadcrumbNameMap,
		} = this.props;
    const { platform } = this.state;
  
    const renderStyle = () => {
      if(pathname == '/user/userSelect'){
        return { background:'#F3F3F3' }
      }else{
        return {
          
        }
      }
    }
		return (
			<DocumentTitle title={getPageTitle(pathname, breadcrumbNameMap)}>
				<div 
          className={styles.container} 
          style={renderStyle()}
        >
					<div className={styles.content} style={{padding:pathname == '/user/userSelect' ? '24px' : pathname == '/user/login' ? '0' : '32px 0 24px 0'}}>{children}</div>
          {
            platform.bottomInfo ? (
              <GlobalFooter links={links} copyright={
                <Fragment>
                {platform.bottomInfo}
                </Fragment>
              } />
            ) : ''
          }
          
				</div>
        
			</DocumentTitle>
		);
	}
}

export default connect(({ menu: menuModel }) => ({
	menuData: menuModel.menuData,
	breadcrumbNameMap: menuModel.breadcrumbNameMap,
}))(UserLayout);
